﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Timers;
using System.Web;
using System.Web.Profile;
using HKB.Common;

/// <summary>
/// global_asax 的摘要说明
/// </summary>
[CompilerGlobalScope]
public class global_asax : HttpApplication
{
    private static bool __initialized;
    protected DefaultProfile Profile
    {
        get
        {
            return (DefaultProfile)base.Context.Profile;
        }
    }
    private void Application_Start(object sender, EventArgs e)
    {
        Timer timer = new Timer();
        timer.Elapsed += new ElapsedEventHandler(this.sysTimer_Elapsed);
        timer.Interval = 60000.0;
        timer.AutoReset = true;
        timer.Enabled = true;
        base.Application["Title"] = "";
    }
    private void sysTimer_Elapsed(object sender, ElapsedEventArgs e)
    {
        base.Application["Title"] = e.SignalTime.ToShortTimeString();
        if (e.SignalTime.ToShortTimeString().Equals("0:00"))
        {
            try
            {
                base.Application["Title"] = "one";
                string fileName = HttpRuntime.AppDomainAppPath + "App_Data/ShopConfig.config";
                DataSet dataSet = new DataSet();
                dataSet.ReadXml(fileName);
                DataTable dataTable = dataSet.Tables[0];
                if (dataTable.Rows.Count > 0)
                {
                    int num = 1;
                    try
                    {
                        num = Convert.ToInt32(dataTable.Rows[0]["FahuoTiem"]);
                    }
                    catch (Exception ex)
                    {
                        num = 0;
                        ex.WriteErrorLog(new string[0]);
                    }
                    if (num != 0)
                    {
                        base.Application["Title"] = num + "天";
                        string cmdText = "exec proc_fahuodingqi " + num.ToString();
                        string connectionString = ConfigurationManager.ConnectionStrings["HowaveConnectionString"].ConnectionString;
                        using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                        {
                            sqlConnection.Open();
                            using (SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection))
                            {
                                sqlCommand.ExecuteNonQuery();
                            }
                        }
                    }
                }
            }
            catch (Exception ex2)
            {
                base.Application["Title"] = ex2.ToString();
            }
        }
    }
    private void Application_End(object sender, EventArgs e)
    {
    }
    private void Application_Error(object sender, EventArgs e)
    {
    }
    private void Session_Start(object sender, EventArgs e)
    {
        base.Session["FavProductID"] = 0;
        base.Session["tag"] = "";
        base.Session["f_id"] = 0;
        base.Session["FavShopID"] = 0;
        base.Session["JuseSaleProduct"] = false;
    }
    private void Session_End(object sender, EventArgs e)
    {
    }
    [DebuggerNonUserCode]
    public global_asax()
    {
        if (!global_asax.__initialized)
        {
            global_asax.__initialized = true;
        }
    }
}